import uploadImg from "@/components/uploadImg"; //上传图片
import chooseMulDisease from "@/components/chooseDisease/chooseMulDisease";
import chooseSingleDisease from "@/components/chooseDisease/chooseSingleDisease";
import chooseSingleDisease2 from "@/components/chooseDisease/chooseSingleDisease2";
import chooseMulDisease2 from "@/components/chooseDisease/chooseMulDisease2";
import chooseFacDoctor from "@/components/chooseFacDoctor";
import chooseMemberDoctor from "@/components/chooseMemberDoctor";
export default {
    components: {
        uploadImg,
        chooseMulDisease,
        chooseSingleDisease,
        chooseSingleDisease2,
        chooseMulDisease2,
        chooseFacDoctor,
        chooseMemberDoctor
    },
    data() {
        return {
            idx: -1,
            status: "", //当前页面状态
            pageTotal: 0, //数据总量
            form: {}, //列表详情
            form1: {}, //原版列表详情
            tableData: [],
            type: "", //add新建
            editVisible: false, //编辑、新建弹框
            moreVisible: false, //其他弹框
            query: {
                name: "", //搜索参数
                page: 1, //页码
                limit: 10, //页数
            },
            loading: false, //全局加载中,
            btnLoading: false, //按钮点击加载中
            state: '', //列表状态
            rules: [],
            timeUnitList: [{
                value: 1,
                label: "天",
            },
            {
                value: 2,
                label: "周",
            },
            {
                value: 3,
                label: "月",
            },
            {
                value: 4,
                label: "年",
            },
            ],
            formType: '', //有值是系统
            sort: 1, //1-最新创建，2-最近更新
            doctorId: "", //医生id
            doctorList: [], //医生列表
            diseaseId: '', //疾病id
            diseaseList: [], //疾病列表
            stateList: [{
                label: '无效',
                value: 0
            },
            {
                label: '待发布',
                value: 1
            },
            {
                label: '已发布',
                value: 2
            },
            ],
            stateList2: [{
                label: '无效',
                value: 0
            },
            {
                label: '待发布',
                value: 1
            },
            {
                label: '执行中',
                value: 2
            },
            {
                label: '结束',
                value: 3
            },
            ],
            doctorMarkList: [{
                label: '护士',
                value: 0
            },
            {
                label: '医生',
                value: 1
            }
            ],
            stateList1: [{
                label: '禁用',
                value: 0
            },
            {
                label: '启用',
                value: 1
            }
            ],
            sourceList: [{
                label: '系统模板',
                value: 1
            },
            {
                label: '自定义',
                value: 2
            }
            ],
            sortList: [{
                label: '最新创建',
                value: 1
            },
            {
                label: '最近更新',
                value: 2
            }
            ],
            clazzList: [{
                value: "0",
                label: "通用问卷",
            },
            {
                value: "1",
                label: "随访问卷",
            },
            {
                value: "2",
                label: "问诊问卷",
            },
            {
                value: "3",
                label: "满意度问卷",
            },
            {
                value: "4",
                label: "调查问卷",
            },
            ],
        }
    },
    computed: {
        isReadyOnly() {
            return (
                (this.form1.state == 2 || this.form1.state == 0) && this.type != "add"
            );
        },
    },
    methods: {
        //弹框关闭事件
        close() {
            this.form = {}; //清空数据
            this.form1 = {}; //清空数据
            this.type = "";
            this.typeState = 0; //取值类型
            this.cascaderShow = false;
            this.$nextTick(() => {
                if (this.$refs.form) {
         
                    this.$refs.form.clearValidate()
                    
                }
                if (this.$refs.Enditor) {
                    this.$refs.Enditor.clearVal();
                }
                if (this.$refs.diseaseBox) {
                    this.$refs.diseaseBox.reset()
                }
                if (this.$refs.doctorBox) {
                    this.$refs.doctorBox.reset()
                }
            })
        },
        //新建
        addItem() {
            this.type = "add"
            this.$nextTick(() => {
                this.cascaderShow = true;
                if (this.$refs.modelDetail) {
                    this.$refs.modelDetail.initShow();
                } else {
                    this.editVisible = true;
                }
            });
        },
        // 删除操作
        handleDelete(index, row, type = "", title = '删除', info) {
            // 二次确认删除
            if (!title) {
                title = "删除"
            }
            let tip = info ? info : "确定要" + title + "？";
            this.$confirm(tip, "提示", {
                type: "warning",
            })
                .then(() => {
                    this.deleteEvent(index, row, type);
                })
                .catch(() => { });
        },
        // 编辑操作
        handleEdit(index, row) {
            this.editVisible = true;
            this.$nextTick(() => {
                this.idx = index;
                this.form = JSON.parse(JSON.stringify(row));
                this.form1 = JSON.parse(JSON.stringify(row));
            })
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, "page", val);
            this.getList();
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, "page", 1);
            this.getList(1);
        },
        // 重置
        handleReset() {
            this.$set(this.query, "name", '');
            this.$set(this.query, "page", 1);
            this.getList(1);
        },
        //富文本编辑器返回值
        editChange(val, name, form) {
            this.$set(this.form, name, val);
            if (val && this.$refs[form]) {
                this.$refs[form].validateField(name);
            }
        },
        //图片上传成功路径
        updateImg(src, name) {
            this.$set(this.form, name, src);
        },
        //获取医生列表
        handelDoctor(val) {
            this.doctorList = val;
        },
        //获取疾病列表
        handelDiseaseList(val) {
            this.diseaseList = val;
        },
        //选择医生
        handelEvent(val, that, name) {
            this.$set(that, name, val);
        },
        //医生名称
        handelLabelEvent(val, that, name) {
            this.$set(that, name, val);
        },
        //医生下拉切换
        handelDoctorIds(val) {
            this.doctorId = val;
            this.$set(this.query, "page", 1);
            this.getList(1);
        },
        //疾病切换刷新
        handelDisease(val) {
            this.diseaseId = val;
            this.$set(this.query, "page", 1);
            this.getList(1);
        },
        isLoading(val) {
            this.loading = val;
        },
        //状态改变刷新列表
        stateHandelEvent() {
            this.$set(this.query, "page", 1);
            this.getList(1);
        },
        //switch切换事件
        handelChange(val, that, name) {
            if (val == true) {
                this.$set(that, name, 1);
            } else {
                this.$set(that, name, 0);
            }
        },
    }
}